#include "GameOverState.h"
#include "MainMenuState.h"
#include "GameplayState.h"
#include "../Game.h"

CGameOverState* CGameOverState::GetInstance()
{
	static CGameOverState s_Instance;
	return &s_Instance;
}

CGameOverState::CGameOverState(void)
{
	m_pD3D	= nullptr;
	m_pTM	= nullptr;
	m_pDI	= nullptr;
	m_pXA	= nullptr;
	m_pFont	= nullptr;

	m_nBackGroundSfxID		= -1;
	m_nCursorMove			= 1;
}

CGameOverState::~CGameOverState(void) { }

void CGameOverState::Enter(void)
{
	//setup the state
	m_pD3D	= CSGD_Direct3D::GetInstance();
	m_pTM	= CSGD_TextureManager::GetInstance();
	m_pDI	= CSGD_DirectInput::GetInstance();
	m_pXA	= CSGD_XAudio2::GetInstance();
	m_pTM	= CSGD_TextureManager::GetInstance();

	m_pFont = new CBitmapFont();
	m_pFont->Load("resources/XML/DeadlyShadowsFont.xml");

	//this->m_nBackGroundSfxID = m_pXA->SFXLoadSound(_T("resource/sounds/CJM_SFXBackGround.xwm"));

}

void CGameOverState::Exit(void)
{
	//if (this->m_nBackGroundSfxID != -1)
	//{
	//	this->m_pXA->SFXStopSound(this->m_nBackGroundSfxID);
	//	this->m_pXA->SFXUnloadSound(this->m_nBackGroundSfxID);
	//	this->m_nBackGroundSfxID = -1;
	//}
	//FONTS
	if (m_pFont != nullptr)
	{
		delete m_pFont;
		m_pFont = nullptr;
	}
}

bool CGameOverState::Input(void)
{
	if (this->m_pDI->KeyPressed(DIK_X))
	{
		CGame::GetInstance()->AddState(CMainMenuState::GetInstance());
		CGame::GetInstance()->RemoveState(this);
		return true;
	}
	return true;
}

void CGameOverState::Update(float fElapsedTime)
{
	//this->m_pXA->Update();
}

void CGameOverState::Render(void)
{
	//BACKGROUND
	//this->m_pD3D->GetSprite()->Flush();

	this->m_pFont->Print("GAME OVER TEST SCREEN", 100, 100, 1.0f, D3DXCOLOR(0,255,0,255));
	this->m_pFont->Print("X to return", 100, 200, 1.0f, D3DXCOLOR(0,255,0,255));
}